﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="QuestionDetail.aspx.vb" Inherits="FishTank.QuestionDetail" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <asp:ScriptManager ID="QuestionDetailScriptManager" runat="server"></asp:ScriptManager>
        <asp:FormView ID="DetailFormView" runat="server" width="100%" CssClass="detailView">
            <EditItemTemplate>
                <h1>Edit question</h1>

                <span class="failureNotification">
                    <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                </span>
                <asp:ValidationSummary ID="QuestionInfoValidationSummary" runat="server" CssClass="failureNotification" 
                     ValidationGroup="QuestionInfoValidationGroup"/>

                <div class="itemInfo">
                <fieldset class="item">
                    <legend>Question Information</legend>
                    <p>
                        <asp:Label ID="TitleLabel" runat="server" AssociatedControlID="TitleTextBox">Title:</asp:Label>
                        <asp:TextBox ID="TitleTextBox" runat="server" CssClass="textEntry"
                                     Text='<%# Bind("Title") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="TitleRequiredValidator" runat="server" ControlToValidate="TitleTextBox" 
                             CssClass="failureNotification" ErrorMessage="Title is required." ToolTip="Title is required." 
                             ValidationGroup="QuestionInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="DescriptionLabel" runat="server" AssociatedControlID="DescriptionTextBox">Question:</asp:Label>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" CssClass="textEntry" TextMode="MultiLine"
                                     Text='<%# Bind("Description") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="DescriptionRequired" runat="server" ControlToValidate="DescriptionTextBox" 
                             CssClass="failureNotification" ErrorMessage="Question description is required." ToolTip="Question description is required." 
                             ValidationGroup="QuestionInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="TagLabel" runat="server" AssociatedControlID="TagTextBox">Tags (comma separated list):</asp:Label>
                        <asp:TextBox ID="TagTextBox" runat="server" CssClass="textEntry" Text='<%# Bind("Tags") %>'></asp:TextBox>
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                        ValidationGroup="QuestionInfoValidationGroup" CausesValidation="False"
                        onclick="CancelEditButton_Click"/>
                    <asp:Button ID="SaveButton" runat="server" CommandName="Save" Text="Save" 
                        ValidationGroup="QuestionInfoValidationGroup" onclick="SaveButton_Click"/>
                </p>
                </div>
            </EditItemTemplate>
            <InsertItemTemplate>
                <h1>Ask a question</h1>

                <span class="failureNotification">
                    <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                </span>
                <asp:ValidationSummary ID="QuestionInfoValidationSummary" runat="server" CssClass="failureNotification" 
                     ValidationGroup="QuestionInfoValidationGroup"/>

                <div class="itemInfo">
                <fieldset class="item">
                    <legend>Question Information</legend>
                    <p>
                        <asp:Label ID="TitleLabel" runat="server" AssociatedControlID="TitleTextBox">Title:</asp:Label>
                        <asp:TextBox ID="TitleTextBox" runat="server" CssClass="textEntry"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="TitleRequiredValidator" runat="server" ControlToValidate="TitleTextBox" 
                             CssClass="failureNotification" ErrorMessage="Title is required." ToolTip="Title is required." 
                             ValidationGroup="QuestionInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="DescriptionLabel" runat="server" AssociatedControlID="DescriptionTextBox">Question:</asp:Label>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" CssClass="textEntry" TextMode="MultiLine"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="DescriptionRequired" runat="server" ControlToValidate="DescriptionTextBox" 
                             CssClass="failureNotification" ErrorMessage="Question description is required." ToolTip="Question description is required." 
                             ValidationGroup="QuestionInfoValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="TagLabel" runat="server" AssociatedControlID="TagTextBox">Tags (comma separated list):</asp:Label>
                        <asp:TextBox ID="TagTextBox" runat="server" CssClass="textEntry"></asp:TextBox>
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                        ValidationGroup="QuestionInfoValidationGroup" CausesValidation="False"
                        PostBackUrl="~/Pages/QuestionList.aspx" />
                    <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" 
                        ValidationGroup="QuestionInfoValidationGroup" onclick="SubmitButton_Click"/>
                </p>
                </div>
            </InsertItemTemplate>
            <ItemTemplate>
                <h1><asp:Label ID="TitleLabel" runat="server" Text="<%# Bind('Title') %>"></asp:Label></h1>

                <p class="author">
                    by
                    <a href="/Pages/MemberDetail.aspx?UserName=<%# Eval("MemberUserName") %>">
                        <asp:Label ID="MemberLabel" runat="server" Text='<%# Bind("MemberFullName") %>' />
                    </a>
                    at
                    <asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Bind("CreatedDateTime", "{0:MMMM d, yyyy}") %>' />
                </p>

                <p class="textBody"><asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description").Replace(Environment.NewLine, "<br />") %>' /></p>
   
                <p class="submitButton">
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" 
                                onclick="DeleteButton_Click" Visible="<%# ModificationPermitted() %>"/>
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" 
                                onclick="EditButton_Click" Visible="<%# ModificationPermitted() %>"/>
                </p>
                           
                <h2>Answers</h2>

                <asp:ListView ID="NestedDetailListView" runat="server">
                    <EmptyDataTemplate>
                        <p>This question is not answered yet!</p>
                    </EmptyDataTemplate>
                    <ItemTemplate>
                        <div class="nestedDetailView">
                            <asp:Rating ID="AnswerRating" runat="server"
                                        CurrentRating='<%# Math.Floor(Eval("AverageRating")) %>'
                                        ReadOnly='<%# Not IsRatingPermitted(Eval("AnswerID")) %>'
                                        MaxRating="5"
                                        CssClass="rating"
                                        StarCssClass='<%# GetStarCssClass(Eval("AnswerID")) %>'
                                        WaitingStarCssClass="ratingStarWaiting"
                                        FilledStarCssClass="ratingStarFilled"
                                        EmptyStarCssClass="ratingStarEmpty"
                                        OnChanged="AnswerRating_Changed"
                                        Tag='<%# Bind("AnswerID") %>' />
                            <p class="author">
                                by
                                <a href="/Pages/MemberDetail.aspx?UserName=<%# Eval("MemberUserName") %>">
                                    <asp:Label ID="MemberLabel" runat="server" Text='<%# Bind("MemberFullName") %>' />
                                </a>
                                at
                                <asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Bind("CreatedDateTime", "{0:MMMM d, yyyy}") %>' />
                            </p>
                            <p  class="textBody">
                                <asp:Label ID="AnswerLabel" runat="server"
                                           Text='<%# Eval("Answer").Replace(Environment.NewLine, "<br />") %>' />
                            </p>
                        </div>
                    </ItemTemplate>
                </asp:ListView>  
            </ItemTemplate>
        </asp:FormView>
</asp:Content>
